package Servlet.camera;

import Dao.UserDao;
import Manage.Camera;
import Utils.mybatisUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

public class camdelandupdServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收从camera绘制的html表单信息,用以删和改
        String streetmsg= request.getParameter("streetmsg");
        String keyword=request.getParameter("keyword");
        String caozuo=request.getParameter("caozuo");
        SqlSession session=mybatisUtils.getSqlSession();
        Camera camera=new Camera();
        if (null!=streetmsg) {
            camera.setStreet(streetmsg);
        }
        camera.setKeyword(Integer.parseInt(keyword));
        UserDao dao=session.getMapper(UserDao.class);
        if ("删".equals(caozuo)){
            //删
            dao.cameradel(Integer.parseInt(keyword),null);
            session.commit();
            response.getWriter().print("操作成功");
        }
        else if ("改".equals(caozuo)) {
            dao.cameraupda(camera);
            session.commit();
            response.getWriter().print("操作成功");
        }
        session.close();
    }
}